package 其他.异位词;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        String[] str={"abc","bca","cfe","cfe","fajif"};
        List<List<String>> list = getWordGroup(str);
        System.out.println(list);
    }
    public static List<List<String>> getWordGroup(String[] str){
        HashMap<String, List<String>> map = new HashMap<>();
        for (int i = 0; i < str.length; i++) {
            String tempValue = str[i];
            char[] chars=tempValue.toCharArray();
            Arrays.sort(chars);

            String key = new String(chars);

            if (map.containsKey(key)){
                map.get(key).add(tempValue);

            }else {
                ArrayList<String> list = new ArrayList<>();
                list.add(tempValue);
                map.put(key,list);
            }
        }
        List<List<String>> list=new ArrayList<>();
        Set<String> set = map.keySet();

        for (String key : set) {
            list.add(map.get(key));
        }
        return list;
    }


}
